import { createPinia } from 'pinia'
import { PERSISTENCE_PREFIX } from '@/constants/cacheEnum'
import { createPersistedState } from 'pinia-plugin-persistedstate'

const pinia = createPinia()

/** 持久化插件
 * 在需要持久化的模块中使用配置
 * { persist: true }
 */
pinia.use(
  createPersistedState({
    key: id => `${PERSISTENCE_PREFIX}_${id}`, // 存储的key
    storage: window.localStorage // 存储方式
  })
)

export default pinia
